package com.itheima.controller;

import com.itheima.pojo.NursingLevel;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.queryParams.NursingLevelParam;
import com.itheima.service.NursingLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/level")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    //条件分页查询
    @GetMapping
    public Result queryAll(NursingLevelParam nursingLevelParam){
        PageResult pageResult = nursingLevelService.queryAll(nursingLevelParam);
        return Result.success(pageResult);
    }

    //添加
    @PostMapping
    public Result addLevel(@RequestBody NursingLevel nursingLevel){
        nursingLevel.setCreateTime(LocalDateTime.now());
        nursingLevel.setUpdateTime(LocalDateTime.now());
        nursingLevelService.save(nursingLevel);
        return Result.success();
    }

    //回显查询
    @GetMapping("/{id}")
    public Result getNursingLevel(@PathVariable Integer id){
        NursingLevel nursingLevel = nursingLevelService.getById(id);
        return Result.success(nursingLevel);
    }

    //修改
    @PutMapping
    public Result updateById(@RequestBody NursingLevel nursingLevel){
        nursingLevelService.updateById(nursingLevel);
        return Result.success();
    }

    //删除
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        nursingLevelService.removeById(id);
        return Result.success();
    }
}
